home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Advanced I⁄O v2.3 / ANSI #includes addenda / streambuf < prev   
Text File  |  1996-02-01  |  5KB  |  165 lines

  1. // streambuf standard header
  2. #ifndef _STREAMBUF_
  3. #define _STREAMBUF_
  4. #include <ios>
  5.  
  6. #if __MWERKS__
  7. #pragma options align=mac68k
  8.  
  9. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  10. #pragma import on
  11. #endif
  12. #endif
  13.  
  14.         // macros
  15. #define EOF    (-1)
  16.         // type streamoff
  17. typedef long streamoff;
  18. const streamoff _BADOFF = -1;
  19.         // class streampos
  20. class streampos {
  21. public:
  22.     streampos(streamoff = 0, const _Fpost * = 0);
  23.     streamoff offset() const;
  24.     operator streamoff (void) const { return offset(); }
  25.     streamoff operator-(const streampos&) const;
  26.     streampos& operator+=(streamoff _O)
  27.         {_Pos += _O; return (*this); }
  28.     streampos& operator-=(streamoff _O)
  29.         {_Pos -= _O; return (*this); }
  30.     streampos operator+(streamoff _O) const
  31.         {streampos s = *this; s += _O; return s; }
  32.     streampos operator-(streamoff _O) const
  33.         {streampos s = *this; s -= _O; return s; }
  34.     _Bool operator==(const streampos&) const;
  35.     _Bool operator!=(const streampos& _R) const
  36.         {return (!(*this == _R)); }
  37.     _Fpost *_Fpos()
  38.         {return (&_Fp); }
  39. private:
  40.     streamoff _Pos;
  41.     _Fpost _Fp;
  42.     };
  43.         // class streambuf
  44. class streambuf {
  45. public:
  46.     virtual ~streambuf();
  47.     virtual int showmany();
  48.     streampos pubseekoff(streamoff _O, ios::seekdir _W,
  49.         ios::openmode _M = ios::in | ios::out)
  50.         {return (seekoff(_O, _W, _M)); }
  51.     streampos pubseekoff(streamoff _O, ios::seek_dir _W,
  52.         ios::open_mode _M)
  53.         {return (pubseekoff(_O, (ios::seekdir)_W, (ios::openmode)_M)); }
  54.     streampos pubseekpos(streampos _P,
  55.         ios::openmode _M = ios::in | ios::out)
  56.         {return (seekpos(_P, _M)); }
  57.     streampos pubseekpos(streampos _P, ios::open_mode _M)
  58.         {return (seekpos(_P, (ios::openmode)_M)); }
  59.     streambuf *pubsetbuf(char *_S, int _N)
  60.         {return (setbuf(_S, _N)); }
  61.     int pubsync()
  62.         {return (sync()); }
  63.     int sbumpc()
  64.         {return (gptr() != 0 && gptr() < egptr()
  65.             ? *_Gn()++ : uflow()); }
  66.     int sgetc()
  67.         {return (gptr() != 0 && gptr() < egptr()
  68.             ? *_Gn() : underflow()); }
  69.     int sgetn(char *_S, int _N)
  70.         {return (xsgetn(_S, _N)); }
  71.     int snextc()
  72.         {return (sbumpc() == EOF ? EOF : sgetc()); }
  73.     int sputbackc(char _C)
  74.         {return (gptr() != 0 && eback() < gptr()
  75.             && _C == gptr()[-1]
  76.             ? *--_Gn() : pbackfail((unsigned char)_C)); }
  77.     int sungetc()
  78.         {return (gptr() != 0 && eback() < gptr()
  79.             ? *--_Gn() : pbackfail()); }
  80.     int sputc(int _C)
  81.         {return (pptr() != 0 && pptr() < epptr()
  82.             ? (*_Pn()++ = _C) : overflow(_C)); }
  83.     int sputn(const char *_S, int _N)
  84.         {return (xsputn(_S, _N)); }
  85.     int in_avail()
  86.         {return (gptr() != 0 && gptr() < egptr()
  87.             ? egptr() - gptr() : showmany()); }
  88. protected:
  89.     streambuf()
  90.         {_Init(); }
  91.     streambuf(ios::_Uninitialized)
  92.         {}
  93.     char *eback() const
  94.         {return (*_IGbeg); }
  95.     char *gptr() const
  96.         {return (*_IGnext); }
  97.     char *egptr() const
  98.         {return (*_IGend); }
  99.     void gbump(int _N)
  100.         {*_IGnext += _N; }
  101.     void setg(char *_B, char *_N, char *_E)
  102.         {*_IGbeg = _B, *_IGnext = _N, *_IGend = _E; }
  103.     char *pbase() const
  104.         {return (*_IPbeg); }
  105.     char *pptr() const
  106.         {return (*_IPnext); }
  107.     char *epptr() const
  108.         {return (*_IPend); }
  109.     void pbump(int _N)
  110.         {*_IPnext += _N; }
  111.     void setp(char *_B, char *_E)
  112.         {*_IPbeg = _B, *_IPnext = _B, *_IPend = _E; }
  113.     void setp(char *_B, char *_N, char *_E)
  114.         {*_IPbeg = _B, *_IPnext = _N, *_IPend = _E; }
  115.     unsigned char *&_Gn()
  116.         {return ((unsigned char *&)*_IGnext); }
  117.     unsigned char *&_Pn()
  118.         {return ((unsigned char *&)*_IPnext); }
  119.     virtual int overflow(int = EOF);
  120.     virtual int pbackfail(int = EOF);
  121.     virtual int underflow();
  122.     virtual int uflow();
  123.     virtual int xsgetn(char *, int);
  124.     virtual int xsputn(const char *, int);
  125.     virtual streampos seekoff(streamoff, ios::seekdir,
  126.         ios::openmode = ios::in | ios::out);
  127.     virtual streampos seekpos(streampos,
  128.         ios::openmode = ios::in | ios::out);
  129.     virtual streambuf *setbuf(char *, int);
  130.     virtual int sync();
  131.     void _Init();
  132.     void _Init(char **, char **, char **, char **, char **,
  133.         char **);
  134. private:
  135.     streambuf(const streambuf&); // undefined
  136.     streambuf& operator=(const streambuf&); // undefined
  137.     char *_Gbeg, *_Gnext, *_Gend;
  138.     char *_Pbeg, *_Pnext, *_Pend;
  139.     char **_IGbeg, **_IGnext, **_IGend;
  140.     char **_IPbeg, **_IPnext, **_IPend;
  141.     };
  142.  
  143. #if __MWERKS__
  144. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  145. #pragma import reset
  146. #endif
  147.  
  148. #pragma options align=reset
  149. #endif
  150.  
  151. #endif
  152.  
  153. /*
  154.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  155.  * Consult your license regarding permissions and restrictions.
  156.  */
  157.  
  158. /* Change log:
  159.  *94June04 PlumHall baseline
  160.  *94Sept30 Applied diffs for Fri Aug 26 00:51:20 1994
  161.  *94Sept30 Applied diffs for Tue Aug 30 07:28:05 1994
  162.  *94Oct07 Inserted MW changes
  163.  *94Dec27mm Added in_avail following pjp.
  164.  */
  165.